<?php
  require_once '../../Helpers/DbHelper.php';
  require_once '../../Controllers/UserController.php';
  require_once '../../Controllers/SchoolController.php';
  require_once '../../Controllers/AdminController.php';
  require_once '../../Helpers/PathHelper.php';
  //
  $u = new UserController();
  $u->evaluatePagePermission(UserController::ADMINISTRATOR);
  //
  $s = new SchoolController();
  $prelemCount = $s->getStudentCount(SchoolController::PRE_ELEMENTARY);
  $elemCount = $s->getStudentCount(SchoolController::ELEMENTARY);
  //
  $c = new AdminController();
  $prelemLevelList = $c->getYearLevelByDepartment(AdminController::PRE_ELEMENTARY);
  //get total receivables from every department.
  $prelem = $s->getReceivablesByDepartment(SchoolController::PRE_ELEMENTARY);
  $elem = $s->getReceivablesByDepartment(SchoolController::ELEMENTARY);
?>
<html>
  <head>
    <title>School Enrolment :: Manage Departments</title>
    <?php
      require_once '../commons.php';
      renderHeaderStyles() ;
    ?>
  </head>
  <body>
  <div class="admin-container">
    <?php renderAdminNav();?>
  </div>
  <div class="container">
    <!--
      TODO:
      - admin can pull records ie total receivables/department, total payment collected/department
      - admin can pull report on the total number of students enrolled per year level
    -->
   	<div class="inner">
		  <h1>REPORTS</h1>
      <table align="center" class="inner card" border="1">
      <tr>
        <th width="400" colspan="2">Student Population by Department</th>
      </tr>
      <tr>
        <td>Pre-Elementary</td>
        <td>Elementary</td>
      </tr>
      <tr>
        <td><?php echo $prelemCount;?></td>
        <td><?php echo $elemCount?></td>
      </tr>
    </table><br /><br />
    <table align="center" class="inner card" border="1">
      <tr>
        <th width="400" colspan="2">Total Collectibles Per Department</th>
      </tr>
      <tr>
        <td>Department</td>
        <td>Amount</td>
      </tr>
      <?php
        /**
        TODO:
        1. create a query to select student balances from a given year level ie. total balances from all kindergarten
        **/
        $sum = 0;
        while($rows=mysql_fetch_assoc($prelem))
        {
          $level = $rows['YearLevelDescription'];
          $sum += $rows['TotalFees'];
          $content = '';
          //
          $content.='<tr><td>'.$level.'</td><td>'.$amount.'</td></tr>';
        }
          echo $content;
      ?>
    </table><br /><br />
    <table align="center" class="inner card" border="0">
      <tr>
        <th width="400" colspan="2">Total Receivables for Elementary Department</th>
      </tr>
      <tr>
        <td>Grade Level</td>
        <td>Amount</td>
      </tr>
      <?php
        /**
        TODO:
        1. create a query to select student balances from a given year level ie. total balances from all kindergarten
        **/
        while($rows=mysql_fetch_assoc($prelemLevelList))
        {
          //print_r($rows);
        }
      ?>
    </table>
		</div>
  </div>
  </body>
</html>